package com.restaurant.application.root.commonui.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class ColumnData implements PickableBean {

    public static final String FN_COLUMNID = "columnId";
    public static final String FN_COLUMNNAME = "columnName";
    public static final String FN_SORTEDUP = "sortedUp";
    public static final String FN_SORTUPPATH = "sortUpPath";
    public static final String FN_SORTDOWNPATH = "sortDownPath";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_COLUMNID,
            FN_COLUMNNAME,
            FN_SORTEDUP,
            FN_SORTUPPATH,
            FN_SORTDOWNPATH);

    private String columnId;
    private String columnName;
    private Boolean sortedUp;
    private String sortUpPath;
    private String sortDownPath;

    public ColumnData(String columnId, String columnName, Boolean sortedUp, String sortUpPath, String sortDownPath) {
        setColumnId(columnId);
        setColumnName(columnName);
        setSortedUp(sortedUp);
        setSortUpPath(sortUpPath);
        setSortDownPath(sortDownPath);
    }

    public ColumnData() {
    }

    public ColumnData duplicate() {
        ColumnData result = new ColumnData();
        result.columnId = this.columnId;
        result.columnName = this.columnName;
        result.sortedUp = this.sortedUp;
        result.sortUpPath = this.sortUpPath;
        result.sortDownPath = this.sortDownPath;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public String getColumnId() {
        return columnId;
    }

    public void setColumnId(String value) {
        this.columnId = value;
    }

    public ColumnData withColumnId(String value) {
        setColumnId(value);
        return this;
    }

    public ColumnData withColumnId(String value, String defaultValue) {
        setColumnId(value == null ? defaultValue : value);
        return this;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String value) {
        this.columnName = value;
    }

    public ColumnData withColumnName(String value) {
        setColumnName(value);
        return this;
    }

    public ColumnData withColumnName(String value, String defaultValue) {
        setColumnName(value == null ? defaultValue : value);
        return this;
    }

    public Boolean getSortedUp() {
        return sortedUp;
    }

    public void setSortedUp(Boolean value) {
        this.sortedUp = value;
    }

    public ColumnData withSortedUp(Boolean value) {
        setSortedUp(value);
        return this;
    }

    public ColumnData withSortedUp(Boolean value, Boolean defaultValue) {
        setSortedUp(value == null ? defaultValue : value);
        return this;
    }

    public String getSortUpPath() {
        return sortUpPath;
    }

    public void setSortUpPath(String value) {
        this.sortUpPath = value;
    }

    public ColumnData withSortUpPath(String value) {
        setSortUpPath(value);
        return this;
    }

    public ColumnData withSortUpPath(String value, String defaultValue) {
        setSortUpPath(value == null ? defaultValue : value);
        return this;
    }

    public String getSortDownPath() {
        return sortDownPath;
    }

    public void setSortDownPath(String value) {
        this.sortDownPath = value;
    }

    public ColumnData withSortDownPath(String value) {
        setSortDownPath(value);
        return this;
    }

    public ColumnData withSortDownPath(String value, String defaultValue) {
        setSortDownPath(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "columnId":
                return getColumnId();
            case "columnName":
                return getColumnName();
            case "sortedUp":
                return getSortedUp();
            case "sortUpPath":
                return getSortUpPath();
            case "sortDownPath":
                return getSortDownPath();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof ColumnData)) return false;
        return signature().equals(((ColumnData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean ColumnData has no signature defined, no hash code or equals possible.");
    }
}
